﻿using NBehave.Spec.NUnit;
using NUnit.Framework;

namespace SilverlightCalculator.Tests
{
    [TestFixture]
    public class When_using_the_ValidatiorBase
    {
        private ValidationBase _validationBase;

        [SetUp]
        public void SetUp()
        {
            _validationBase = new ValidationBase();
        }

        [Test]
        public void IsValid_should_return_false_when_errors_exist()
        {
            // Arrange
            _validationBase.AddError("propertyName", "message");

            // Act
            var result = _validationBase.IsValid();

            // Assert
            result.ShouldBeFalse();
        }

        [Test]
        public void IsValid_should_return_true_when_no_errors_exist()
        {
            // Arrange
            // collection will be empty at this point

            // Act
            var result = _validationBase.IsValid();

            // Assert
            result.ShouldBeTrue();
        }

        [Test]
        public void IsPropertyValid_should_return_false_if_error_exists()
        {
            // Arrange
            _validationBase.AddError("propertyName", "message");

            // Act
            var result = _validationBase.IsPropertyValid("propertyName");

            // Assert
            result.ShouldBeFalse();
        }

        [Test]
        public void IsPropertyValid_should_return_true_if_error_does_not_exist()
        {
            // Arrange
            // collection will be empty at this point

            // Act
            var result = _validationBase.IsPropertyValid("X");

            // Assert
            result.ShouldBeTrue();
        }

        [Test]
        public void Should_be_able_to_return_message_for_error()
        {
            // Arrange
            _validationBase.AddError("propertyName", "message");

            // Act
            var result = _validationBase.GetErrorMessageForProperty("propertyName");

            // Assert
            result.ShouldEqual("message");
        }

        [Test]
        public void Should_return_null_if_message_does_not_exist_for_error()
        {
            // Arrange
            // collection will be empty at this point

            // Act
            var result = _validationBase.GetErrorMessageForProperty("propertyName");

            // Assert
            result.ShouldBeNull();
        }
    }
}